package com.sinai.mshab.server;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 * This is a basic email class. It should be extended for custom emails. Please
 * set up the mail_host, mail_user, and mail_password variables before use.
 * 
 * @author serge
 * 
 */
public class Email {

	public static String mail_host, mail_user, mail_password;

	public Email(String to, String subject, String html_content) {
		Properties props = new Properties();
		props.setProperty("mail.transport.protocol", "smtp");
		props.setProperty("mail.host", mail_host);
		props.setProperty("mail.user", mail_user);
		props.setProperty("mail.password", mail_password);

		Session mailSession = Session.getDefaultInstance(props, null);
		try {
			Transport transport = mailSession.getTransport();

			MimeMessage message = new MimeMessage(mailSession);
			message.setSubject(subject);
			message.setContent(html_content, "text/html; charset=ISO-8859-1");
			message.addRecipient(Message.RecipientType.TO, new InternetAddress(
					to));

			transport.connect();
			transport.sendMessage(message, message
					.getRecipients(Message.RecipientType.TO));
			transport.close();
		} catch (Exception e) {

		}
	}
}